#@layout2()
#define main()
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-query">
                <form class="layui-form" id="query_form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-mid">名称：</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="name" autocomplete="off" class="layui-input"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button class="layui-btn layui-btn-blue" type="button" function="query"><i class="layui-icon">&#xe615;</i>查询</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <table id="fsDatagrid" lay-filter="fsDatagrid" class="fsDatagrid" toolbar="#toolbarDemo" title="课程列表" defaultToolbar="filter" isTotalRow="1" isLoad="1" url="#(base)/stucourse/setCoursePage?studentid=#(studentid)"
                   isPage="1" sortType="1" pageSize="10" defaultForm="query_form"></table>

            <div class="fsDatagridCols">
                <p type="numbers" title="序号"/>
                <p field="id" title="ID" />
                <p field="Kcid" title="课程编号" />
                <p field="Kcname" title="课程名称" />
                <p field="Periodexpriment" title="讲课学时" />
                <p field="Creidt" title="总学分" />
                <p field="Coursetype" title="课程类型" templet="#stateTpl" />
                <p field="isselecd" title="状态" templet="#stateTpl1" />
            </div>
            
            <script type="text/html" id="stateTpl">
                {{ d.Coursetype == 1 ? '必修' : '选修' }}
            </script>
            
            <script type="text/html" id="stateTpl1">
  				<input type="checkbox" name="isselecd" lay-filter="switchTest" value="{{d.id}}" lay-skin="switch"  lay-text="选择|关闭" {{ d.isselecd == 2 ? 'checked disabled' : '' }}>
			</script>

        </div>
    </div>
</div>
<script type="text/javascript">
layui.use('form', function(){
	var form = layui.form;
	form.on('switch(switchTest)', function(data){
	var fromdata = data;
	console.log(data.elem); //得到checkbox原始DOM对象
	console.log(data.elem.checked); //是否被选中，true或者false
	console.log(data.value); //复选框value值，也可以通过data.elem.value得到
	console.log(data.othis); //得到美化后的DOM对象
	var loginload = layer.load();
	if(data.elem.checked){
		$.ajax({
			type:"POST",
			url:"/stucourse/setstudentcourse",
			dataType:"json",
			data:{
				courseid : data.value
				},
			success:function(data){
				layer.close(loginload);
				console.log(data)
				if(data.state == 'ok'){
					$(fromdata.elem).addClass("layui-btn-disabled");
					$(fromdata.elem).attr("disabled","disabled");
					layer.msg(data.msg, {icon: 1,anim: 0});
				}else{
					layer.msg(data.msg, {icon: 2,anim: 6});
				}
			},
			error:function(jqXHR){
				layer.close(loginload);
				layer.msg("发生错误："+jqXHR.status, {icon: 2,anim: 6});
				console.log("发生错误："+jqXHR.status);
			}
		});
	}
		  
	});    
})
</script>

#end